Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 1a7288517e4635f93d835e26793e1a0c209cbfaa


Parents : c62f751
Author : Mark Qvist <bc7291552be7a58f361522990465165c>
Signature : T66BB85Valid, signed by author
Date : 2026-05-28T14:37:14+02:00

Fixed link and mention scans happening inside code blocks

Changes

1 files changed, 22 insertions(+), 0 deletions(-)


Diff

diff --git a/nomadnet/ui/textui/Channels.py b/nomadnet/ui/textui/Channels.py
index 05e67f6..24bba5b 100644
--- a/nomadnet/ui/textui/Channels.py
+++ b/nomadnet/ui/textui/Channels.py
@@ -136,10 +136,32 @@ def _scan_nick_mentions(text, own_nick):
if nick.lower() != own_nick:
yield m.start(), m.end(), f"nick_mention", nick
+def _scan_code_blocks(text):
+ regions = []
+ fence_re = re.compile(r'```[^\n]*\n.*?```', re.DOTALL)
+ for m in fence_re.finditer(text): regions.append((m.start(), m.end()))
+
+ inline_re = re.compile(r'(?<!`)`[^`\n]+`')
+ for m in inline_re.finditer(text):
+ if not any(s <= m.start() < e for s, e in regions):
+ regions.append((m.start(), m.end()))
+
+ regions.sort()
+ return regions
+
def _body_markup(body, body_attr="body_text", own_nick=None, check_links=True):
+ code_blocks = _scan_code_blocks(body)
spans = list(_scan_links(body))
spans.extend(_scan_mentions(body, own_nick))
spans.extend(_scan_nick_mentions(body, own_nick))
+
+ def overlaps_code(span_start, span_end):
+ for r_start, r_end in code_blocks:
+ if span_start < r_end and span_end > r_start: return True
+ return False
+
+ spans = [(s, e, k, t) for s, e, k, t in spans if not overlaps_code(s, e)]
+
spans.sort(key=lambda s: s[0])
filtered = []
last_end = 0


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────